cc.Class({
    extends: cc.Component,
	
	createBoomEffect(block,game){
		var nodeV = game.node.convertToNodeSpaceAR(cc.v2(block.x,block.y));
		var starnode2 = cc.instantiate(game.effectBoom);
		game.effectTop.addChild(starnode2);
		starnode2.setPosition(nodeV.x,nodeV.y);
		starnode2.zIndex=100;
		game.boomArr.push(starnode2);
	},
	
	createOneceEffect(tempMp,game,startx,starty,time){
		var nodeV = game.node.convertToNodeSpaceAR(cc.v2(tempMp.x,tempMp.y));
		var starnode1 = cc.instantiate(game.effectStar);
		game.effectTop.addChild(starnode1);
		starnode1.setPosition(startx,starty);
		starnode1.runAction(cc.moveTo(time,nodeV));
		starnode1.zIndex=100;
		return starnode1;
	},

    createEffect(effectBlock,game){
		
		var nodeV = game.node.convertToNodeSpaceAR(cc.v2(effectBlock.x,effectBlock.y));
			
		var sx = nodeV.x,sy = nodeV.y;
		
		if(effectBlock.type2 == 2){//上下
				
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,0,600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,0,-600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5;
				
			}else if(effectBlock.type2 == 3){//右斜
			
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,-600,game.tgnmb*600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,600,-game.tgnmb*600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5
				
			}else if(effectBlock.type2 == 4){//左斜
			
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,600,game.tgnmb*600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,-600,-game.tgnmb*600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5
				
			}else if(effectBlock.type2 == 5){//三角形
			
				
				var p=[[sx-(game.w-game.w2)/2-game.w2,sy-3*game.h/2],[sx+game.w+game.w2,sy],[sx-(game.w-game.w2)/2-game.w2,sy+3*game.h/2],[sx-(game.w-game.w2)/2-game.w2,sy-3*game.h/2]];
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(p[0][0],p[0][1]);
				starnode1.runAction(cc.sequence(cc.moveTo(0.15,p[1][0],p[1][1]),
												cc.moveTo(0.15,p[2][0],p[2][1]),
												cc.moveTo(0.15,p[3][0],p[3][1])));
				starnode1.zIndex=100;
				
				game.effectArr.push(starnode1);
				
				return 0.5
				
			}else if(effectBlock.type2 == 6){//花
				
				var p=[[sx-(game.w-game.w2)/2-game.w2,sy-3*game.h/2],[sx+game.w+game.w2,sy],[sx-(game.w-game.w2)/2-game.w2,sy+3*game.h/2]];
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(p[0][0],p[0][1]);
				starnode1.runAction(cc.sequence(cc.moveTo(0.25,p[1][0],p[1][1]),
												cc.moveTo(0.25,p[2][0],p[2][1])));
				starnode1.zIndex=100;
				
				var p2=[[sx+(game.w-game.w2)/2+game.w2,sy-3*game.h/2],[sx-game.w-game.w2,sy],[sx+(game.w-game.w2)/2+game.w2,sy+3*game.h/2]];
				var starnode2 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(p2[0][0],p2[0][1]);
				starnode2.runAction(cc.sequence(cc.moveTo(0.25,p2[1][0],p2[1][1]),
												cc.moveTo(0.25,p2[2][0],p2[2][1])));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5
				
				
			}else if(effectBlock.type2 == 7){//五角星
				
				var p=[[sx,sy+2*game.h],[sx,sy-2*game.h]];
				var starnode1 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(p[0][0],p[0][1]);
				starnode1.runAction(cc.moveTo(0.5,p[1][0],p[1][1]));
				starnode1.zIndex=100;
				
				var p2=[[sx-game.w-game.w2,sy+game.h],[sx+game.w+game.w2,sy-game.h]];
				var starnode2 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(p2[0][0],p2[0][1]);
				starnode2.runAction(cc.moveTo(0.35,p2[1][0],p2[1][1]));
				starnode2.zIndex=100;
				
				var p3=[[sx+game.w+game.w2,sy+game.h],[sx-game.w-game.w2,sy-game.h]];
				var starnode3 = cc.instantiate(game.effectStar);
				game.effectTop.addChild(starnode3);
				starnode3.setPosition(p3[0][0],p3[0][1]);
				starnode3.runAction(cc.moveTo(0.25,p3[1][0],p3[1][1]));
				starnode3.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				game.effectArr.push(starnode3);
				
				return 0.5
				
			}else if(effectBlock.type2 == 8){//彩球
				var mparr = this.getNewAddBlock(effectBlock,game);
				
				effectBlock.blockNode.zIndex=200;
				
				for(var i = 0 ;i<mparr.length;i++){
					
					var starnode2 = cc.instantiate(game.effectStar);
					
					var nodeV1 = game.node.convertToNodeSpaceAR(cc.v2(mparr[i].x,mparr[i].y));
					
					game.effectTop.addChild(starnode2);
					starnode2.setPosition(sx,sy);
					starnode2.runAction(cc.sequence(cc.delayTime(0.1*(i+1)),cc.moveTo(0.2,nodeV1.x,nodeV1.y)));
					starnode2.zIndex=100;
					game.effectArr.push(starnode2);
				}
				
				return 0.1*(mparr.length+1)+0.2;
				
			}else if(effectBlock.type2 == 9){//上下
				
				var starnode1 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,0,600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,0,-600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5;
				
			}else if(effectBlock.type2 == 10){//右斜
			
				var starnode1 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,-600,game.tgnmb*600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,600,-game.tgnmb*600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5
				
			}else if(effectBlock.type2 == 11){//左斜
			
				var starnode1 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode1);
				starnode1.setPosition(nodeV.x,nodeV.y);
				starnode1.runAction(cc.moveBy(0.5,600,game.tgnmb*600));
				starnode1.zIndex=100;
				
				var starnode2 = cc.instantiate(game.effectStarBig);
				game.effectTop.addChild(starnode2);
				starnode2.setPosition(nodeV.x,nodeV.y);
				starnode2.runAction(cc.moveBy(0.5,-600,-game.tgnmb*600));
				starnode2.zIndex=100;
				
				game.effectArr.push(starnode1);
				game.effectArr.push(starnode2);
				
				return 0.5
				
			}
			
			return 0;
	},
	
	getNewAddBlock(effectBlock,game){
		
		var mapPointArr = game.mapPointArr;
		var newAddBlock = [];
		
		if(effectBlock.type2 == 2){//上下
				
				/*
				var tblock = effectBlock.mpU;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpU;
				}
				
				tblock = effectBlock.mpD;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpD;
				}*/
				
				for(var i=0;i<mapPointArr.length;i++){
					if(mapPointArr[i].x==effectBlock.x&&mapPointArr[i].y!=effectBlock.y){
						newAddBlock.push(mapPointArr[i]);
					}
				}
				
			}else if(effectBlock.type2 == 3){//右斜
				
				/*
				var tblock = effectBlock.mpUL;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpUL;
				}
				
				tblock = effectBlock.mpDR;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpDR;
				}*/
				
				var ex = effectBlock.x,ey = effectBlock.y;
				
				for(var i=0;i<mapPointArr.length;i++){
					
					var tmp = mapPointArr[i];
					
					if(tmp.x!=ex){
						var tmpx = tmp.x,tmpy=tmp.y;
						if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey)*(-1)){
							newAddBlock.push(tmp);
						}
					}
					
				}
				
			}else if(effectBlock.type2 == 4){//左斜
				
				/*
				var tblock = effectBlock.mpUR;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpUR;
				}
				
				tblock = effectBlock.mpDL;
				while(tblock!=null){
					newAddBlock.push(tblock);
					tblock=tblock.mpDL;
				}*/
				
				var ex = effectBlock.x,ey = effectBlock.y;
				
				for(var i=0;i<mapPointArr.length;i++){
					
					var tmp = mapPointArr[i];
					
					if(tmp.x!=ex){
						var tmpx = tmp.x,tmpy=tmp.y;
						if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey)){
							newAddBlock.push(tmp);
						}
					}
					
				}
				
			}else if(effectBlock.type2 == 5){//三角形
				
				/*
				if(effectBlock.mpU!=null){
					newAddBlock.push(effectBlock.mpU);
					if(effectBlock.mpU.mpUL!=null){
						newAddBlock.push(effectBlock.mpU.mpUL);
					}
				}
				
				if(effectBlock.mpUL!=null){
					newAddBlock.push(effectBlock.mpUL);
					if(effectBlock.mpUL.mpU!=null){
						newAddBlock.push(effectBlock.mpUL.mpU);
					}
				}
				
				if(effectBlock.mpD!=null){
					newAddBlock.push(effectBlock.mpD);
					if(effectBlock.mpD.mpDL!=null){
						newAddBlock.push(effectBlock.mpD.mpDL);
					}
				}
				
				if(effectBlock.mpDL!=null){
					newAddBlock.push(effectBlock.mpDL);
					if(effectBlock.mpDL.mpD!=null){
						newAddBlock.push(effectBlock.mpDL.mpD);
					}
				}
				
				if(effectBlock.mpUR!=null){
					newAddBlock.push(effectBlock.mpUR);
					if(effectBlock.mpUR.mpDR!=null){
						newAddBlock.push(effectBlock.mpUR.mpDR);
					}
				}
				
				if(effectBlock.mpDR!=null){
					newAddBlock.push(effectBlock.mpDR);
					if(effectBlock.mpDR.mpUR!=null){
						newAddBlock.push(effectBlock.mpDR.mpUR);
					}
				}*/
				
				var ex = effectBlock.x,ey = effectBlock.y;
				var parr = [
								[ex,ey+game.h],[ex,ey-game.h],
								[ex-game.w/2-game.w2/2,ey+game.h*3/2],
								[ex-game.w/2-game.w2/2,ey+game.h/2],
								[ex-game.w/2-game.w2/2,ey-game.h/2],
								[ex-game.w/2-game.w2/2,ey-game.h*3/2],
								[ex+game.w/2+game.w2/2,ey+game.h/2],
								[ex+game.w/2+game.w2/2,ey-game.h/2],
								[ex+game.w+game.w2,ey]
							];
							
				for(var i=0;i<parr.length;i++){
					
					for(var j=0;j<mapPointArr.length;j++){
					
						var tmp = mapPointArr[j];
						
						if(tmp.x==parr[i][0]&&tmp.y==parr[i][1]){
							newAddBlock.push(tmp);
							break;
						}
						
					}
					
				}
				
				
			}else if(effectBlock.type2 == 6){//花
				
				/*
				if(effectBlock.mpU!=null){
					newAddBlock.push(effectBlock.mpU);
					if(effectBlock.mpU.mpUL!=null){
						newAddBlock.push(effectBlock.mpU.mpUL);
					}
					if(effectBlock.mpU.mpUR!=null){
						newAddBlock.push(effectBlock.mpU.mpUR);
					}
				}
				
				if(effectBlock.mpUL!=null){
					newAddBlock.push(effectBlock.mpUL);
					if(effectBlock.mpUL.mpU!=null){
						newAddBlock.push(effectBlock.mpUL.mpU);
					}
					if(effectBlock.mpUL.mpDL!=null){
						newAddBlock.push(effectBlock.mpUL.mpDL);
					}
				}
				
				if(effectBlock.mpD!=null){
					newAddBlock.push(effectBlock.mpD);
					if(effectBlock.mpD.mpDL!=null){
						newAddBlock.push(effectBlock.mpD.mpDL);
					}
					if(effectBlock.mpD.mpDR!=null){
						newAddBlock.push(effectBlock.mpD.mpDR);
					}
				}
				
				if(effectBlock.mpDL!=null){
					newAddBlock.push(effectBlock.mpDL);
					if(effectBlock.mpDL.mpD!=null){
						newAddBlock.push(effectBlock.mpDL.mpD);
					}
					if(effectBlock.mpDL.mpUL!=null){
						newAddBlock.push(effectBlock.mpDL.mpUL);
					}
				}
				
				if(effectBlock.mpUR!=null){
					newAddBlock.push(effectBlock.mpUR);
					if(effectBlock.mpUR.mpDR!=null){
						newAddBlock.push(effectBlock.mpUR.mpDR);
					}
					if(effectBlock.mpUR.mpU!=null){
						newAddBlock.push(effectBlock.mpUR.mpU);
					}
				}
				
				if(effectBlock.mpDR!=null){
					newAddBlock.push(effectBlock.mpDR);
					if(effectBlock.mpDR.mpUR!=null){
						newAddBlock.push(effectBlock.mpDR.mpUR);
					}
					if(effectBlock.mpDR.mpD!=null){
						newAddBlock.push(effectBlock.mpDR.mpD);
					}
				}*/
				
				var ex = effectBlock.x,ey = effectBlock.y;
				var parr = [
								[ex,ey+game.h],[ex,ey-game.h],
								
								[ex-game.w/2-game.w2/2,ey+game.h*3/2],
								[ex-game.w/2-game.w2/2,ey+game.h/2],
								[ex-game.w/2-game.w2/2,ey-game.h/2],
								[ex-game.w/2-game.w2/2,ey-game.h*3/2],
								
								
								[ex+game.w/2+game.w2/2,ey+game.h*3/2],
								[ex+game.w/2+game.w2/2,ey+game.h/2],
								[ex+game.w/2+game.w2/2,ey-game.h/2],
								[ex+game.w/2+game.w2/2,ey-game.h*3/2],
								
								
								[ex+game.w+game.w2,ey],
								[ex-game.w-game.w2,ey]
							];
							
				for(var i=0;i<parr.length;i++){
					
					for(var j=0;j<mapPointArr.length;j++){
					
						var tmp = mapPointArr[j];
						
						if(tmp.x==parr[i][0]&&tmp.y==parr[i][1]){
							newAddBlock.push(tmp);
							break;
						}
						
					}
					
				}
				
				
			}else if(effectBlock.type2 == 7){//五角星
				
				/*
				var tblock = effectBlock.mpU;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpU!=null){
						newAddBlock.push(tblock.mpU);
					}
				}
				
				tblock = effectBlock.mpD;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpD!=null){
						newAddBlock.push(tblock.mpD);
					}
				}
				
				tblock = effectBlock.mpUR;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpUR!=null){
						newAddBlock.push(tblock.mpUR);
					}
				}
				
				tblock = effectBlock.mpUL;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpUL!=null){
						newAddBlock.push(tblock.mpUL);
					}
				}
				
				tblock = effectBlock.mpDR;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpDR!=null){
						newAddBlock.push(tblock.mpDR);
					}
				}
				
				var tblock = effectBlock.mpDL;
				if(tblock!=null){
					newAddBlock.push(tblock);
					if(tblock.mpDL!=null){
						newAddBlock.push(tblock.mpDL);
					}
				}*/
				
				var ex = effectBlock.x,ey = effectBlock.y;
				var parr = [
								[ex,ey+game.h],[ex,ey-game.h],
								[ex,ey+game.h*2],[ex,ey-game.h*2],
								
								//[ex-game.w/2-game.w2/2,ey+game.h*3/2],
								[ex-game.w/2-game.w2/2,ey+game.h/2],
								[ex-game.w-game.w2,ey+game.h],
								
								[ex-game.w/2-game.w2/2,ey-game.h/2],
								[ex-game.w-game.w2,ey-game.h],
								//[ex-game.w/2-game.w2/2,ey-game.h*3/2],
								
								
								//[ex+game.w/2+game.w2/2,ey+game.h*3/2],
								[ex+game.w/2+game.w2/2,ey+game.h/2],
								[ex+game.w+game.w2,ey+game.h],
								[ex+game.w/2+game.w2/2,ey-game.h/2],
								[ex+game.w+game.w2,ey-game.h]
								//[ex+game.w/2+game.w2/2,ey-game.h*3/2],
								
								
								
							];
							
				for(var i=0;i<parr.length;i++){
					
					for(var j=0;j<mapPointArr.length;j++){
					
						var tmp = mapPointArr[j];
						
						if(tmp.x==parr[i][0]&&tmp.y==parr[i][1]){
							newAddBlock.push(tmp);
							break;
						}
						
					}
					
				}
				
			}else if(effectBlock.type2==8){
				
				for(var i=0;i<game.mapPointArr.length;i++){
					if(game.mapPointArr[i].type1==effectBlock.type1){
						newAddBlock.push(game.mapPointArr[i]);
					}
				}
				
			}else if(effectBlock.type2==9){
				
				for(var i=0;i<mapPointArr.length;i++){
					if(
						(mapPointArr[i].x==effectBlock.x||mapPointArr[i].x==effectBlock.x+game.w/2+game.w2/2||mapPointArr[i].x==effectBlock.x-game.w/2-game.w2/2)
						&&mapPointArr[i].y!=effectBlock.y
						){
						newAddBlock.push(mapPointArr[i]);
					}
				}
				
			}else if(effectBlock.type2==10){
				
				var ex = effectBlock.x,ey = effectBlock.y;
				
				for(var i=0;i<mapPointArr.length;i++){
					
					var tmp = mapPointArr[i];
					
					if(tmp.x!=ex){
						var tmpx = tmp.x,tmpy=tmp.y;
						
						if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey)*(-1)){
							newAddBlock.push(tmp);
						}else if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey-game.h)*(-1)){
							newAddBlock.push(tmp);
						}else if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey+game.h)*(-1)){
							newAddBlock.push(tmp);
						}
					}
					
				}
				
			}else if(effectBlock.type2==11){
				
				var ex = effectBlock.x,ey = effectBlock.y;
				
				for(var i=0;i<mapPointArr.length;i++){
					
					var tmp = mapPointArr[i];
					
					if(tmp.x!=ex){
						var tmpx = tmp.x,tmpy=tmp.y;
						if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey)){
							newAddBlock.push(tmp);
						}else if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey+game.h)){
							newAddBlock.push(tmp);
						}else if((tmpx-ex)*game.h == (game.w2+game.w)*(tmpy-ey-game.h)){
							newAddBlock.push(tmp);
						}
					}
					
				}
				
			}
			
			//排除不能被消除的
			for(var i=0;i<newAddBlock.length;){
				if(newAddBlock[i].type1>6){
					newAddBlock.splice(i,1);
				}else{
					i++;
				}
			}
			
			return newAddBlock;
	}
});
